package com.hh.servlet;

import com.hh.module.CompanyModule;
import com.hh.module.ContactModule;
import com.hh.module.NavModule;
import com.hh.service.ContactService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

@WebServlet("/contact")
public class ContactServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//          1、乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
//          2、获取前端数据
//          3、封装前端获取的数据
//          4、逻辑处理
        ContactService contactService = new ContactService();
//          5、逻辑处理后的返回
        //公司信息
        CompanyModule companyModule = LogoServlet.logo();
        req.setAttribute("companyModule",companyModule);
        //公司联系方式
        List<ContactModule> contactList = contactService.getContactList();
        req.setAttribute("contactList",contactList);

        //导航栏
        List<NavModule> navModuleList = NavServlet.nav();
        req.setAttribute("navModuleList", navModuleList);
//          6、页面转发
        req.getRequestDispatcher("/contact.jsp").forward(req, resp);
    }
}
